<template>
  <div id="sidebar">
    <router-link to="/">Home</router-link>
    <br />
    <router-link to="/ClickEvent-Ref">Click Event Ref 实现</router-link>
    <br />
    <router-link to="/ClickEvent-Reactive">
      Click Event Reactive 实现
    </router-link>
    <br />
    <router-link to="/LifeCycle">LifeCycle</router-link>
    <br />
    <router-link to="/Watch">Watch</router-link>
    <br />
    <router-link to="/Computed">Computed</router-link>
    <br />
    <router-link to="/NowTime">NowTime</router-link>
    <br />
    <router-link to="/Teleport">Teleport</router-link>
    <br />
    <router-link to="/Async">Suspense</router-link>
    <br />
    <router-link to="/ComponentPractice">组件化实践</router-link>
    <br />
  </div>
  <div id="container">
    <!--    <keep-alive><router-view /></keep-alive>-->
    <router-view v-slot="{ Component }">
      <transition v-if="isTransition">
        <keep-alive v-if="isKeepAlive">
          <component :is="Component" />
        </keep-alive>
        <component v-else :is="Component" />
      </transition>
      <keep-alive v-else-if="isKeepAlive">
        <component :is="Component" />
      </keep-alive>
      <component v-else :is="Component" />
    </router-view>
  </div>
</template>

<script lang="ts">
  import { defineComponent, reactive } from 'vue';

  export default defineComponent({
    setup: () => {
      return reactive({
        isTransition: false,
        isKeepAlive: true
      });
    }
  });
</script>

<style lang="scss">
  #app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    color: #2c3e50;
    display: flex;
  }

  #sidebar {
    flex-grow: 1;
    padding: 30px;
    margin-right: 30px;
    border: 1px black solid;

    a {
      font-weight: bold;
      color: #2c3e50;

      &.router-link-exact-active {
        color: #42b983;
      }
    }
  }

  #container {
    border: 1px black solid;
    flex-grow: 4;
  }
</style>
